package org.komarichin.jdo.persistence;


import org.komarichin.beans.IUser;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * Created by IntelliJ IDEA.
 * User: Michael Komarichin
 * Date: 04.10.2009
 * Time: 10:29:44
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User implements IUser {
    private static final long serialVersionUID = -7254481465237572329L;
    @PrimaryKey
    @Persistent(valueStrategy = javax.jdo.annotations.IdGeneratorStrategy.IDENTITY)
    private Long id;
    @Persistent
    private String login;
    @Persistent
    private String password;
    @Persistent
    private String hint;
    @Persistent
    private Long role;

    public User() {
    }

    public User(Long id, String login, String password, String hint, Long role) {
        this.id = id;
        this.login = login;
        this.password = password;
        this.hint = hint;
        this.role = role;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getLogin() {
        return login;
    }

    @Override
    public void setLogin(String login) {
        this.login = login;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String getHint() {
        return hint;
    }

    @Override
    public void setHint(String hint) {
        this.hint = hint;
    }

    @Override
    public Long getRole() {
        return role;
    }

    @Override
    public void setRole(Long role) {
        this.role = role;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("User");
        sb.append("{id=").append(id);
        sb.append(", login='").append(login).append('\'');
        sb.append(", password='").append(password).append('\'');
        sb.append(", hint='").append(hint).append('\'');
        sb.append(", role=").append(role);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof User)) return false;

        User user = (User) o;

        if (hint != null ? !hint.equals(user.hint) : user.hint != null) return false;
        if (id != null ? !id.equals(user.id) : user.id != null) return false;
        if (!login.equals(user.login)) return false;
        if (password != null ? !password.equals(user.password) : user.password != null) return false;
        if (role != null ? !role.equals(user.role) : user.role != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + login.hashCode();
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (hint != null ? hint.hashCode() : 0);
        result = 31 * result + (role != null ? role.hashCode() : 0);
        return result;
    }
}
